package problem724;

//724.寻找数组的中心下标
//https://leetcode.cn/problems/find-pivot-index/submissions/578401262/

import java.util.Arrays;

class Solution {
    public int pivotIndex(int[] nums) {
        int n = nums.length;
        int[] sum1 = new int[n+1];
        int[] sum2 = new int[n+1];
        for(int i = 1, j = n-1; i<=n; i++, j--) {
            sum1[i] = sum1[i-1] + nums[i-1];
            sum2[j] = sum2[j+1] + nums[j];
        }
        System.out.println(Arrays.toString(sum1));
        System.out.println(Arrays.toString(sum2));
        for(int i = 0; i<n; i++) {
            if(sum1[i] == sum2[i+1]) return i;
        }
        return -1;
    }
}